package com.yitao.cms.service.order;

import com.google.common.collect.Lists;
import com.skipper.base.service.GenericEntityService;
import com.yitao.client.dto.order.MallOrderRefundImgDto;
import com.yitao.client.model.order.MallOrderRefundImgModel;
import com.yitao.client.model.order.QMallOrderRefundImgModel;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import java.util.List;

@Service
public class CmsMallOrderRefundImgService extends GenericEntityService<MallOrderRefundImgModel, MallOrderRefundImgDto, QMallOrderRefundImgModel> {
    public CmsMallOrderRefundImgService(EntityManager entityManager) {
        super(entityManager);
    }

    public List<MallOrderRefundImgDto> getMallOrderRefundImgDtoByRefundId(Long refundId) {
        List<MallOrderRefundImgDto> mallOrderRefundImgDtos = Lists.newArrayList();
        List<MallOrderRefundImgModel> mallOrderRefundImgModelList = queryFactory.select(Q).from(Q).where(Q.refundId.eq(refundId)).fetch();
        if (mallOrderRefundImgModelList != null && mallOrderRefundImgModelList.size() != 0) {
            MallOrderRefundImgDto mallOrderRefundImgDto = null;
            for (MallOrderRefundImgModel mallOrderRefundImgModel : mallOrderRefundImgModelList) {
                mallOrderRefundImgDto = new MallOrderRefundImgDto();
                BeanUtils.copyProperties(mallOrderRefundImgModel, mallOrderRefundImgDto);
                mallOrderRefundImgDtos.add(mallOrderRefundImgDto);
            }
        }
        return mallOrderRefundImgDtos;
    }
}
